2020-2021 Sunseeker Telemetry and Lighting System
adc10_a_ex7_repeatSingleDMA.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 #include "driverlib.h"
33 
34 //******************************************************************************
67 //******************************************************************************
68 
69 void main (void)
70 {
71  uint16_t ADC_Result[64];
72  volatile uint16_t ADC_Result_Average;
73  uint8_t i;
74  uint16_t ADC_Result_sum;
75 
76  //Stop Watchdog Timer
77  WDT_A_hold(WDT_A_BASE);
78 
79  //Initialize the ADC10_A Module
80  /*
81  * Base Address for the ADC10_A Module
82  * Use internal ADC10_A bit as sample/hold signal to start conversion
83  * USE MODOSC 5MHZ Digital Oscillator as clock source
84  * Use default clock divider of 1
85  */
86  ADC10_A_init(ADC10_A_BASE,
87  ADC10_A_SAMPLEHOLDSOURCE_SC,
88  ADC10_A_CLOCKSOURCE_ADC10OSC,
89  ADC10_A_CLOCKDIVIDER_1);
90 
91  ADC10_A_enable(ADC10_A_BASE);
92 
93  /*
94  * Base Address for the ADC10_A Module
95  * Sample/hold for 16 clock cycles
96  * Enable Multiple Sampling
97  */
98  ADC10_A_setupSamplingTimer(ADC10_A_BASE,
99  ADC10_A_CYCLEHOLD_16_CYCLES,
100  ADC10_A_MULTIPLESAMPLESENABLE);
101 
102  //Configure Memory Buffer
103  /*
104  * Base Address for the ADC10_A Module
105  * Use input A1
106  * Use positive reference of AVcc
107  * Use negative reference of AVss
108  */
109  ADC10_A_configureMemory(ADC10_A_BASE,
110  ADC10_A_INPUT_A1,
111  ADC10_A_VREFPOS_AVCC,
112  ADC10_A_VREFNEG_AVSS);
113 
114  //Initialize and Setup DMA Channel 0
115  /*
116  * Configure DMA channel 0
117  * Configure channel for repeated single transfer
118  * DMA interrupt flag will be set after every 64 transfers
119  * Use DMA Trigger Source 24 (ADC10IFG)
120  * Transfer Word-to-Word
121  * Trigger upon Rising Edge of Trigger Source Signal
122  */
123  DMA_initParam param = {0};
124  param.channelSelect = DMA_CHANNEL_0;
125  param.transferModeSelect = DMA_TRANSFER_REPEATED_SINGLE;
126  param.transferSize = 64;
127  param.triggerSourceSelect = DMA_TRIGGERSOURCE_24;
128  param.transferUnitSelect = DMA_SIZE_SRCWORD_DSTWORD;
129  param.triggerTypeSelect = DMA_TRIGGER_RISINGEDGE;
130  DMA_init(&param);
131  /*
132  * Configure DMA channel 0
133  * Use ADC10_A Memory Buffer as source
134  * Increment destination address after every transfer
135  */
136  DMA_setSrcAddress(DMA_CHANNEL_0,
137  ADC10_A_getMemoryAddressForDMA(ADC10_A_BASE),
138  DMA_DIRECTION_UNCHANGED);
139  /*
140  * Base Address for the DMA Module
141  * Configure DMA channel 0
142  * Use ADC_Result[0] as destination
143  * Increment destination address after every transfer
144  */
145  DMA_setDstAddress(DMA_CHANNEL_0,
146  (uint32_t)(uintptr_t)&ADC_Result[0],
147  DMA_DIRECTION_INCREMENT);
148 
149  //Enable DMA channel 0 interrupt
150  DMA_clearInterrupt(DMA_CHANNEL_0);
151  DMA_enableInterrupt(DMA_CHANNEL_0);
152 
153  //Enable transfers on DMA channel 0
154  DMA_enableTransfers(DMA_CHANNEL_0);
155 
156  while (1)
157  {
158  //Enable and Start the conversion
159  //in Repeated Single-Channel Conversion Mode
160  ADC10_A_startConversion(ADC10_A_BASE,
161  ADC10_A_REPEATED_SINGLECHANNEL);
162 
163  __bis_SR_register(CPUOFF + GIE); //LPM0, ADC10_A_ISR will force exit
164  __no_operation(); //For debug only
165 
166  //Clear accumulate register
167  ADC_Result_sum = 0x0;
168  for (i = 0; i < 64; i++){
169  ADC_Result_sum += ADC_Result[i];
170  }
171 
172  //Average of 64 conversions results
173  ADC_Result_Average = ADC_Result_sum >> 6;
174 
175  //SET BREAKPOINT HERE to be able to watch ADC_Result_Average
176  //Delay before next 64 conversions
177  __delay_cycles(50000);
178  }
179 }
180 
181 
182 // DMA interrupt service routine
183 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
184 __interrupt
185 #elif defined(__GNUC__)
186 __attribute__((interrupt(DMA_VECTOR)))
187 #endif
188 void DMA0_ISR (void) {
189  switch (__even_in_range(DMAIV,16)){
190  case 0: break; //No interrupt
191  case 2: //DMA0IFG
192  //64 conversions complete
193  //Disable Conversions without pre-empting any conversions taking place.
194  ADC10_A_disableConversions(ADC10_A_BASE,
195  ADC10_A_PREEMPTCONVERSION);
196  //Exit LPM
198  break;
199  case 4: break; //DMA1IFG
200  case 6: break; //DMA2IFG
201  default: break;
202  }
203 }
MPU_initThreeSegmentsParam param
void main(void)
void DMA0_ISR(void)
__no_operation()
__bic_SR_register_on_exit(LPM3_bits|GIE)
__delay_cycles(500000)